package com.ruoyi.cm.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cm.domain.vo.CmBaSettleDeductDetailVo;
import com.ruoyi.cm.domain.bo.CmBaSettleDeductDetailBo;
import com.ruoyi.cm.service.ICmBaSettleDeductDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 其他计量详情
 *
 * @author zyb
 * @date 2024-09-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cm/baSettleDeductDetail")
public class CmBaSettleDeductDetailController extends BaseController {

    private final ICmBaSettleDeductDetailService iCmBaSettleDeductDetailService;

    /**
     * 查询其他计量详情列表（站点）
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<CmBaSettleDeductDetailVo> list(CmBaSettleDeductDetailBo bo, PageQuery pageQuery) {
        return iCmBaSettleDeductDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询其他计量详情列表（标段）
     */
    @SaCheckLogin
    @GetMapping("/bdlist")
    public R<List<CmBaSettleDeductDetailVo>> bdlist(CmBaSettleDeductDetailBo bo) {
        return R.ok(iCmBaSettleDeductDetailService.bdlist(bo));
    }

    /**
     * 导出其他计量详情列表
     */
    @SaCheckLogin
    @Log(title = "其他计量详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CmBaSettleDeductDetailBo bo, HttpServletResponse response) {
        List<CmBaSettleDeductDetailVo> list = iCmBaSettleDeductDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "其他计量详情", CmBaSettleDeductDetailVo.class, response);
    }

    /**
     * 获取其他计量详情详细信息
     *
     * @param deductDetailId 主键
     */
    @SaCheckLogin
    @GetMapping("/{deductDetailId}")
    public R<CmBaSettleDeductDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long deductDetailId) {
        return R.ok(iCmBaSettleDeductDetailService.queryById(deductDetailId));
    }

    /**
     * 新增其他计量详情
     */
    @SaCheckLogin
    @Log(title = "其他计量详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CmBaSettleDeductDetailBo bo) {
        return toAjax(iCmBaSettleDeductDetailService.insertByBo(bo));
    }

    /**
     * 修改其他计量详情
     */
    @SaCheckLogin
    @Log(title = "其他计量详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CmBaSettleDeductDetailBo bo) {
        return toAjax(iCmBaSettleDeductDetailService.updateByBo(bo));
    }

    /**
     * 删除其他计量详情
     *
     * @param deductDetailIds 主键串
     */
    @SaCheckLogin
    @Log(title = "其他计量详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deductDetailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] deductDetailIds) {
        return toAjax(iCmBaSettleDeductDetailService.deleteWithValidByIds(Arrays.asList(deductDetailIds), true));
    }
}
